//
//  ViewController.m
//  11-uiview和核心动画区别
//
//  Created by J on 16/2/24.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *grayView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));

//    CABasicAnimation* ani = [CABasicAnimation animation];
//    ani.keyPath = @"position";
//    ani.toValue = [NSValue valueWithCGPoint:CGPointMake(50, 300)];
//    ani.removedOnCompletion = NO;
//    ani.fillMode = kCAFillModeForwards;
//    ani.delegate = self;//不用遵守协议 比较特殊
//    [_grayView.layer addAnimation:ani forKey:nil];
    
    
    //注意: UIView动画必须通过改变属性的真实值,才有动画效果 如果以后动画不需要与用户交互通常用核心动画(转场)

    [UIView animateWithDuration:0.25 animations:^{
        

        _grayView.layer.position = CGPointMake(50, 300);
        
    } completion:^(BOOL finished) {
        
        NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));
    }];

}

- (void)animationDidStart:(CAAnimation *)anim{
    
}

//注意: 核心动画一切都是假象 并不会真实地改变图层的属性值

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
//    NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));
}
@end
